this.main = function() {
	var mainwidth = frame_center.getInnerWidth() - 4;
	var mainheight = frame_center.getInnerHeight();

	var treeLoader = new Ext.tree.TreeLoader({
				dataUrl : basepath
						+ '../sysControl/permission/GroupController/functree.do',
				baseAttrs : {
					uiProvider : Ext.ux.TreeCheckNodeUI
				}
			})
	var tree = new Ext.tree.TreePanel({
		height : mainheight - 260,
		animate : false,
		rootVisible : true,
		autoScroll : true,
		listeners : {
			'checkchange' : function(node, checked) {
				if (node.parentNode != null) {
					node.cascade(function(node) {
								node.attributes.checked = checked;
								node.ui.checkbox.checked = checked;
								return true;
							});
					var pNode = node.parentNode;
					if (checked == true) {
						if(pNode.isRoot!==true){
							var cb = pNode.ui.checkbox;
							if (cb) {
								cb.checked = checked;
								cb.defaultChecked = checked;
							}
							pNode.attributes.checked = checked;
						}
					} else {
						var _miss = false;
						for (var i = 0; i < pNode.childNodes.length; i++) {
							if (pNode.childNodes[i].attributes.checked != checked)
								_miss = true;
						}
						if (!_miss) {
							pNode.ui.toggleCheck(checked);
							pNode.attributes.checked = checked;
						}
					}
				}
			}
		},
		loader : treeLoader

	});
	tree.setRootNode(new Ext.tree.AsyncTreeNode({
				text : '请选择',
				checkbox:false,
				draggable : true,
				id : 'source'
			}));

	var sm = new Ext.grid.CheckboxSelectionModel({
				singleSelect : false
			});

	var cm = new Ext.grid.ColumnModel([sm, {
				id : 'groupcode',
				header : '组代码',
				dataIndex : 'groupcode',
				width : 100,
				sortable : true
			}, {
				id : 'groupname',
				header : '组名称',
				dataIndex : 'groupname',
				width : 110,
				sortable : true
			}, {
				id : 'startmark',
				header : '启用状态',
				renderer : formatStratmark,
				dataIndex : 'startmark',
				width : 60,
				sortable : true
			}, {
				id : 'groupdescription',
				header : '组描述',
				dataIndex : 'groupdescription',
				width : 160,
				sortable : true
			}, {
				id : 'createusername',
				header : '创建人',
				dataIndex : 'createusername',
				width : 110,
				sortable : true
			}, {
				id : 'createtime',
				header : '创建时间',
				dataIndex : 'createtime',
				width : 150,
				sortable : true
			}]);

	var dataRecord = Ext.data.Record.create([{
				name : 'groupid',
				type : 'string'
			}, {
				name : 'groupcode',
				type : 'string'
			}, {
				name : 'groupname',
				type : 'string'
			}, {
				name : 'groupdescription',
				type : 'string'
			}, {
				name : 'createusername',
				type : 'string'
			}, {
				name : 'createtime',
				type : 'string'
			}, {
				name : 'startmark',
				type : 'string'
			}]);

	var formPanel = new Ext.form.FormPanel({
				labelAlign : 'right',
				title : '添加角色组',
				frame : true,
				border : false,
				collapsible : true,
				region : 'east',
				width : 360,
				labelWidth : 64,
				submitUrl : basepath
						+ "../sysControl/permission/GroupController/add.do",
				items : [{
							xtype : 'fieldset',
							title : '组基本信息',
							frame : false,
							border : true,
							items : [{
										name : "groupcode",
										width : 240,
										xtype : "textfield",
										fieldLabel : "组代码",
										allowBlank : false,
										blankText : "组代码编号不可以为空!"
									}, {
										name : "groupname",
										width : 240,
										xtype : "textfield",
										fieldLabel : "组名称",
										allowBlank : false,
										blankText : "组名称编号不可以为空!"
									}, {
										xtype : 'combo',
										width : 240,
										name : 'startmarkname',
										fieldLabel : "启用状态",
										displayField : 'text',
										valueField : 'value',
										hiddenName : 'startmark',
										value : '1',
										store : new Ext.data.SimpleStore({
													fields : ['text', 'value'],
													data : [['未启用', '0'],
															['启用', '1']]
												}),
										mode : 'local',
										editable : false,
										triggerAction : 'all'
									}, {
										name : "groupdescription",
										width : 240,
										xtype : "textfield",
										fieldLabel : "组描述"
									}, {
										name : "groupid",
										xtype : "hidden"
									}, {
										name : "funcids",
										xtype : "hidden"
									}]
						}, {
							xtype : 'fieldset',
							title : '组菜单设置',
							frame : false,
							border : true,
							items : [tree]
						}]

			});

	var store = new Ext.data.Store({
		autoLoad : {
			params : {
				start : 0,
				limit : 30
			}
		},
		proxy : new Ext.data.HttpProxy({
					url : basepath
							+ '../sysControl/permission/GroupController/queryPage.do'

				}),

		reader : new Ext.data.JsonReader({
					totalProperty : 'results',
					root : "items",
					id : 'groupid'
				}, dataRecord)
	});

	var pagingBar = new Ext.PagingToolbar({// 分页工具栏
		store : store,
		pageSize : 30,// 每页显示的条数。用于系统自动计算它的start值
		displayInfo : true,
		displayMsg : '数据从第{0}条 - 第{1} 条 共 {2}条数据',
		emptyMsg : "没有记录"

	});
	var grid = new Ext.ux.grid.LockingGridPanel({
				cm : cm,
				sm : sm,
				store : store,
				region : 'center',
				bbar : pagingBar
			});

	function getTreeChecked(node,values){
		var echildren=node.childNodes==null||node.childNodes.length===0?(node.attributes==null?node.children:node.attributes.children):node.childNodes;
		if(echildren!=null&&echildren.length!==0){
			var nodee=null;
			for(var i=0;i<echildren.length;i++){
				nodee=echildren[i];
				if(nodee.attributes!=null)
					nodee=nodee.attributes;
				if(nodee.checked===true){
					values.push(nodee.id);
					getTreeChecked(nodee,values);
				}
			}
		}
	
	}
			
	var displayPanel = new Ext.Panel({
		width : mainwidth,
		height : mainheight,
		layout : 'border',
		renderTo : "divLlist" + this.menuid,
		items : [grid, formPanel],

		tbar : [{
			text : '添加',
			iconCls : 'table_add',
			handler : function() {
				formPanel.setTitle("添加角色组");
				formPanel.getForm().reset();
				formPanel.getForm().setValues({
							pfuncid : ""
						});
				formPanel.submitUrl = basepath
						+ "../sysControl/permission/GroupController/add.do";
				treeLoader.baseParams['groupid'] = null;
				tree.root.reload();
			}
		}, {
			text : '修改',
			iconCls : 'table_edit',
			handler : function() {
				var record = grid.getSelectionModel().getSelections();
				if (record.length <= 0) {
					Ext.MessageBox.alert('提示', '请选择需要修改的记录');
					return;
				} else if (record.length > 1) {
					Ext.MessageBox.alert('提示', '最多只能选择一行记录');
					return;
				}

				formPanel.submitUrl = basepath
						+ "../sysControl/permission/GroupController/update.do"
				formPanel.setTitle("修改角色组");
				formPanel.getForm().setValues(record[0].data);
				treeLoader.baseParams['groupid'] = record[0].data.groupid;
				tree.root.reload();
			}
		}, {
			text : '保存',
			iconCls : 'table_save',
			handler : function() {
				var funcids=[];
				getTreeChecked(tree.root,funcids);
				formPanel.getForm().findField("funcids").setValue(funcids.join(","));
				submitFormPanel(formPanel, formPanel.submitUrl, function(form,
								action) {
							Ext.Msg.alert("提示", action.result.info);
							store.reload();
						});

			}
		}, {
			text : '删除',
			iconCls : 'table_delete',
			handler : function() {
				var rs = grid.getSelectionModel().getSelections();
				if (!rs || rs.length <= 0) {
					Ext.Msg.alert("提示", "请选择可用需要删除的记录");
					return;
				}

				var ids = "";
				for (var i = 0; i < rs.length; i++) {
					if (i != 0)
						ids += "&";
					ids += "ids=" + rs[i].data.groupid;
				}
				deleteData(
						basepath
								+ "../sysControl/permission/GroupController/delete.do",
						ids, store, '你确定要删除选择的选择的角色组吗？');
			}
		}, '->', closebtn]
	});
	var groupname = new Ext.form.TextField({});
	var groupcode = new Ext.form.TextField({});

			var tbar2 = new Ext.Toolbar({
				renderTo : displayPanel.tbar,
				items : ['组名',groupname,'组编码',groupcode,
						{ text:'查询',iconCls:'table_find',tooltip : '查询',
					  	handler : function() {
					  			addStoreBaseParams(groupname,'groupname',store);
					  			addStoreBaseParams(groupcode,'groupcode',store);
								store.load({params:{start:0,limit:30}});
						}
				}]
			});
	destroyResize(displayPanel,[tbar2]);
}
